package hello;

import java.util.Iterator;
import java.util.Map;

public class HashMap {
    public static void main(String[] args) {
        Map<Integer, String> map = new java.util.HashMap<Integer, String>();
        map.put(1, "a");
        map.put(2, "b");
        map.put(3, "c");
        map.put(4, "d");
        map.put(5, "e");
        //第一种
        for (Integer in : map.keySet()) {//map.KeySet()获取所有的key的集合
            String str = map.get(in);
            System.out.println(in + " " + str);
        }
        //第二种
        Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Integer, String> entry = it.next();
            System.out.println("key=" + entry.getKey() + ",value=" + entry.getValue());
        }
        //第三种
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            System.out.println("key=" + entry.getKey() + ",value=" + entry.getValue());
        }
        for (Integer in : map.keySet()) {
            String str = map.get(in);
            System.out.println("key=" + in + ",value=" + str);
        }
        //  Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Integer, String> entry = it.next();
            System.out.println("key=" + entry.getKey() + ",value=" + entry.getValue());
        }
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            System.out.println("key=" + entry.getKey() + ",value=" + entry.getValue());
        }
    }
}
